package com.jdk.demo.fileChannel.openfile;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

public class Read {
	
	// READ：打开以进行读取访问
	public static void main(String[] args) throws Exception {
		File file = new File("o2.txt");
		Path path = file.toPath();
		FileChannel fileChannel = FileChannel.open(path, StandardOpenOption.READ);
		byte[] byteArray = new byte[(int)file.length()];
		ByteBuffer buffer = ByteBuffer.wrap(byteArray);
		fileChannel.read(buffer);
		
		byteArray = buffer.array();
		for (int i = 0; i < byteArray.length; i++) {
			System.out.print((char)byteArray[i]);
		}
		
		fileChannel.close();
	}

}
